/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Net.Server;
//import javaapplication2.Service;
 import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

/**
 *
 * @author Administrator
 */
public class ServerIMP {
    
   
    ArrayList<String > Filelist = new ArrayList<String>(); 
    //int top;
    int port = 8821;
    //int [] count = new count
    ServerIMP(){
        start();
    }
    void start() {
        Socket s = null;
        String filePath;
        try {
            ServerSocket ss = new ServerSocket(port);
            
            while (true) {
                // 选择进行传输的文件
               
               
               
                filePath="text.txt" ;
                //s = ss.accept(); 
                netSocket client = new netSocket(ss);
                System.out.println("建立socket链接");
                read(client);

             
                //s.close();                
                System.out.println("文件传输完成");
                
            }
          
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
  public void read(netSocket client){
   while(true){  
       try {   if(client.read().startsWith("downLoad")) 
            client.write("end");
            client.UpLoad("text.txt");
            break;
        } catch (Exception ex) {
           ex.printStackTrace();
                 
        }
   }
       while (true) {
    try {
      if(client.read().startsWith("CCD")){
          
      client.write("BOUND");System.out.println("1");
      client.downLoad();
      client.downLoad();
          break ;
      }    
        } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     break;
    }
   } 
   }
 

/**
public void  initPath(){
    Filelist.add("text.txt ") ;
   //Filelist.add("");
  // Filelist.add("");
}*/
    public static void main(String arg[]) throws Exception {
       //ServerIMP sever = 
        String filePath="text.txt" ;
               new ServerIMP();
     
    }
}

    

